/*
 * Copyright 2020-2030 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/
package com.gitee.minimalismstyle.fresh.tms.service.impl

import com.gitee.minimalismstyle.fresh.common.core.domain.R
import com.gitee.minimalismstyle.fresh.common.data.beetl.service.impl.LongModelBaseServiceImpl
import com.gitee.minimalismstyle.fresh.flowable.api.feign.TasksApi
import com.gitee.minimalismstyle.fresh.flowable.api.feign.model.TaskActionRequest
import com.gitee.minimalismstyle.fresh.flowable.api.model.FlowSubmitData
import com.gitee.minimalismstyle.fresh.tms.dao.TmsTaskReadyDao
import com.gitee.minimalismstyle.fresh.tms.api.model.TmsTaskReady
import com.gitee.minimalismstyle.fresh.tms.api.service.TmsTaskReadyService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Primary
import org.springframework.stereotype.Service

/**
 * 预备任务业务实现
 * @author maoxiaodong
*/
@Primary
@Service
class TmsTaskReadyServiceImpl: TmsTaskReadyService, LongModelBaseServiceImpl<TmsTaskReadyDao, TmsTaskReady>() {

    //@Autowired
    //lateinit var tasksApi: TasksApi

    override fun submit(flowSubmitData: FlowSubmitData<TmsTaskReady>): R<FlowSubmitData<TmsTaskReady>> {
        save(flowSubmitData.t)
        val validateR = submitValidate(flowSubmitData)
        if (validateR.success){
            return validateR
        }
        val taskActionRequest = TaskActionRequest()
        //val r = tasksApi.executeTaskAction(flowSubmitData.taskAction.taskId!!, taskActionRequest)
        return R.success(flowSubmitData)
    }

    private fun submitValidate(flowSubmitData: FlowSubmitData<TmsTaskReady>): R<FlowSubmitData<TmsTaskReady>> {
        val r = R(data = flowSubmitData)
        return  r
    }
}